import request from "./request";

const baseURL = '/'
// 通用接口
const list = (module = "", seachForm) => {
  return request.doRequest(`${baseURL}${module}/list`, {params: seachForm})
};

const find = (module = "", modelId) => {
  return request.doRequest(`${baseURL}${module}/find/${modelId}`, {})
};

const save = (module = "", model) => {
  return request.doRequest(`${baseURL}${module}/save`, {method: 'POST', data: model})
};

const update = (module = "", model) => {
  return request.doRequest(`${baseURL}${module}/update`, {method: "POST", data: model})
};

const del = (module = "", modelId) => {
  return request.doRequest(`${baseURL}${module}/delete/${modelId}`, {})
};

// 选项数据接口
const siteOptions = () => {
  return request.doRequest(`${baseURL}btsite/options`, {})
}

const categoryOptions = () => {
  return request.doRequest(`${baseURL}category/options`, {})
}

const clientOptions = () => {
  return request.doRequest(`${baseURL}client/options`, {})
}

const libraryOptions = () => {
  return request.doRequest(`${baseURL}library/options`, {})
}

// 上传下载接口
const upload = (formData) => {
  return request.doRequest(`${baseURL}resource/upload`, {method: 'POST', data: formData})
};
const download = (params) => {
  return request.doRequest(`${baseURL}resource/download`, {params: params, blob: true})
};

const api = {
  list, find, save, update, del,
  siteOptions, categoryOptions, clientOptions, libraryOptions,
  upload, download
};

export default api;
